<?php
class str implements iterator{
    public $str = [];
    public function __construct($str)
    {
        if(is_string($str)){
            $str = str_split($str);
        }
        $this->str = $str;
    }
    public function rewind()
    {
        reset($this->str);

        
    }

    public function valid()
    {
        return key($this->str)===null?false:true;
        
    }

    public function current()
    {
        return current($this->str);
       
    }
    public function key()
    {
        return key($this->str);
       
    }
    public function next()
    {
        next($this->str);
     
    }
}
$str = new str("helloworld!");
foreach($str as $k=>$v){
    echo "[$k]"."=>"."[$v]"."<br>";
}